﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIS Domestic
// Created By:     Parker Zhou(parkerz@wicresoft.com)
// Created Date:   2011-2-12
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Business.CIS;

namespace BEGDC.CC.Web.CIS2.Domestic.Admin
{
    public partial class CustomerCount : System.Web.UI.Page
    {
        private static string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];

        protected void Page_Load(object sender, EventArgs e)
        {
            btnExport.Click += new EventHandler(btnExport_Click);
            DataGrid1.ItemDataBound += new DataGridItemEventHandler(DataGrid1_ItemDataBound);
            DataGrid2.ItemDataBound += new DataGridItemEventHandler(DataGrid2_ItemDataBound);
            if (!Page.IsPostBack)
            {
                LevelDropDownList.SelectedIndex = 0;
            }

            int levelValue = -1;
            if(!string.IsNullOrEmpty(LevelDropDownList.SelectedItem.Value))
                levelValue = Convert.ToInt32(LevelDropDownList.SelectedValue);

            DataGrid1.DataSource = CustomerCountHelper.GetCustomerCountInfo(connStr, levelValue);
            DataGrid2.DataSource = DataGrid1.DataSource;
            DataGrid1.DataBind();
            DataGrid2.DataBind();
        }

        protected void DataGrid2_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            DataGrid dg = sender as DataGrid;
            if (e.Item.ItemType == ListItemType.Header)
            {
                int n = e.Item.Cells.Count;
                int m = n - 1;
                e.Item.Cells[0].Text = @"Province<br/>省份";
                //e.Item.Cells[n - 2].Text = @"Average<br/>平均值";
                e.Item.Cells[n - 1].Text = @"Total<br/>总计";
            }
        }

        protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            //throw new NotImplementedException();
            DataGrid dg = sender as DataGrid;
            if (e.Item.ItemType == ListItemType.Header)
            {
                int n = e.Item.Cells.Count;
                int m = n - 1;
                e.Item.Cells[0].Text = @"";
                //e.Item.Cells[n - 2].Text = @"Average<br/>平均值";
                e.Item.Cells[n - 1].Text = @"Total<br/>总计";
            }
            else //if (e.Item.ItemType == ListItemType.Item)
            {
                e.Item.Visible = false;
            }

        }


        protected void btnExport_Click(object sender, EventArgs e)
        {
            BEGDC.CC.Web.Control.ExportDataGridToExcel.Export(Page, DataGrid2, "Customer_Statistics.xls");
        }
    }
}
